<template>
    <div>
        <el-table :data="list" style="width: 100%" max-height="500">
            <el-table-column fixed prop="rooms.roomId" label="房间ID" width="150">
            </el-table-column>
            <el-table-column prop="hotelName" label="所属酒店" width="120" show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column prop="rooms.roomPrice" label="房间单价" width="120">
            </el-table-column>
            <el-table-column prop="rooms.roomDescription" label="房间描述" width="120" :formatter="formatRole">
            </el-table-column>


            <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="pageDto.page" :page-sizes="[5, 10, 20, 30, 50]" :page-size="pageDto.size"
                layout="total, sizes, prev, pager, next, jumper" :total="100">
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    name: "roomtable",
    data() {
        return {
            pageDto: { page: 1, size: 10, hotels: {} },
            list: [],
            displayList: [],
        }
    },
    methods: {
        // element ui
        // 分页
        handleSizeChange(val) {
            this.pageDto.size = val;
            this.queryByPage();
        },
        handleCurrentChange(val) {
            this.pageDto.page = val;
            this.queryByPage();
        },
        // 删除
        handleDelete(row) {
            this.$api.roomsApi.deleteById({ roomId: row.rooms.roomId }).then(res => {
                if (res.data.code == 1) {
                    this.$notify({
                        title: "成功",
                        message: "数据删除成功！",
                        type: "success",
                    });
                } else {
                    this.$notify.error({
                        title: "错误",
                        message: "数据删除失败！",
                    });
                }
            })
            this.queryByPage();
        },

        // 请求参数
        queryByPage() {
            this.$api.roomsApi.queryByPage(this.pageDto).then(res => {
                this.list = res.data.data;
                // this.displayList = this.list.map(item=>item.users)
                // console.log(this.displayList);
            })
        },
    },
    mounted() {
        this.queryByPage();
    },
}
</script>